package cn.fl.audit.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.audit.condition.AudPayPassOpinionQueryCondition;
import cn.fl.audit.constant.AudStandingBookConstant;
import cn.fl.audit.service.IAudPayPassOpinionService;
import cn.fl.audit.vo.AudPayPassOpinionVO;
import cn.fl.capital.service.ICapPayInfoService;
import cn.fl.capital.vo.CapPayInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.IAuditPayPassOpinionService;
import cn.fl.preloan.condition.AuditPayPassOpQueryCondition;
import cn.fl.preloan.dto.audit.AddAudPayPassOpRequest;
import cn.fl.preloan.dto.audit.AudPayPassOpListRequest;
import cn.fl.preloan.dto.audit.AuditPayPassOpinionDTO;
import cn.fl.preloan.dto.audit.ModifyAudPayPassOpRequest;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.SystemConstant;
import cn.fl.commons.result.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * @Description: 放款通过意见表 控制层
 */
@Controller
@RequestMapping("/audit/audPayPassOpinion")
public class AudPayPassOpinionController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AudPayPassOpinionController.class);

	/**
	 * AudPayPassOpinion 服务层BEAN
	 */
	@Autowired
	private IAudPayPassOpinionService audPayPassOpinionService;
	
	/**
	 * 付款信息服务
	 */
	@Autowired
	private ICapPayInfoService capPayInfoService;
	
	/**
	 * 项目信息服务
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	
	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;

	@Autowired
	private IAuditPayPassOpinionService auditPayPassOpinionService;
	
	/**
	 * 到信审通过意见预览页面
	 */
	@RequestMapping(value = "/toPreviewPage.do", method = { RequestMethod.GET})
	public ModelAndView toPreviewPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toPreviewPage", "到信审通过意见预览页面.", CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/audCreditPassOpinionPreviewPage");
		String id = request.getParameter("id");
		String flag = request.getParameter("flag");
		String previewString = "";
		if(StringUtils.isNotEmpty(id) && StringUtils.isNotEmpty(flag)){
			if(flag.equals("dy")){
				previewString = this.audPayPassOpinionService.getPreviewStringForDy(Long.valueOf(id));
			}
			if(flag.equals("ht")){
				previewString = this.audPayPassOpinionService.getPreviewStringForHt(Long.valueOf(id));
			}
			if(flag.equals("htForCar")){
				previewString = this.audPayPassOpinionService.getPreviewStringForHtForCar(Long.valueOf(id));
			}
			if(flag.equals("dyForCar")){
				previewString = this.audPayPassOpinionService.getPreviewStringForDyForCar(Long.valueOf(id));
			}
			if(flag.equals("htForBus")){
				previewString = this.audPayPassOpinionService.getPreviewStringForHtForBus(Long.valueOf(id));
			}
			if(flag.equals("htForXny")){
				previewString = this.audPayPassOpinionService.getPreviewStringForHtForXny(Long.valueOf(id));
			}
			if(flag.equals("dyForXny")){
				previewString = this.audPayPassOpinionService.getPreviewStringForDyForXny(Long.valueOf(id));
			}
		}
		view.addObject("previewString", previewString);
		return view;
	}

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("audit/audPayPassOpinion/list");
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到放款通过意见页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String capPayId = request.getParameter("capPayId");//付款信息ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		String opnTypCd = request.getParameter("opnTypCd");//放款意见类型(合同/抵押)
		String carAudit = request.getParameter("carAudit");//乘用车放款标识
		String busAudit = request.getParameter("busAudit");//专车放款标识
		String procNm = request.getParameter("procNm");//流程定义名称
		String payTypCd = request.getParameter("payTypCd");//放款类型
		if(StringUtils.isEmpty(opnTypCd)) {
			BaseLogUtils.info(logger, "toModifyPage", "跳转放款通过意见页面,放款意见类型不能为空.", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//查询付款信息
		CapPayInfoVO capPayInfoVO= new CapPayInfoVO();
		Long payTypCdq = 0L;
		Long payStsCd = 0L;
		if(StringUtils.isNotEmpty(capPayId)){
			capPayInfoVO = this.capPayInfoService.selectById(Long.valueOf(capPayId));
			payTypCdq = Long.valueOf(capPayInfoVO.getPayTypCd());
			payStsCd = Long.valueOf(capPayInfoVO.getPayStsCd());
		}
		ModelAndView view = new ModelAndView();
		if(StringUtils.isNotEmpty(carAudit)){
			String buOrgCd = capPayInfoVO.getBuOrgCd();
			if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_CONTRACT)){
				if(PropertiesCacheUtils.getProperty(SystemConstant.FL_BUS_XNY_ORG_CD).equals(buOrgCd)){
					view = new ModelAndView("audit/audPayPassOpinion/xnyPayContractOpinionAdd");
				}else{
					view = new ModelAndView("audit/audPayPassOpinion/carPayContractOpinionAdd");
				}
			}else if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_MORTGAGE)){
				if(PropertiesCacheUtils.getProperty(SystemConstant.FL_BUS_XNY_ORG_CD).equals(buOrgCd)){
					view = new ModelAndView("audit/audPayPassOpinion/xnyPayMortgageOpinionAdd");
				}else{
					view = new ModelAndView("audit/audPayPassOpinion/carPayMortgageOpinionAdd");
				}
			}
		}else if(StringUtils.isNotEmpty(busAudit)){
			if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_CONTRACT)){
				view = new ModelAndView("audit/audPayPassOpinion/busPayContractOpinionAdd");
			}else if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_MORTGAGE)){
				view = new ModelAndView("audit/audPayPassOpinion/payMortgageOpinionAdd");
			}
		}else{
			if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_CONTRACT)){
				view = new ModelAndView("audit/audPayPassOpinion/payContractOpinionAdd");
			}else if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_MORTGAGE)){
				view = new ModelAndView("audit/audPayPassOpinion/payMortgageOpinionAdd");
			}
		}
		view.addObject("payStsCd",payStsCd);
		view.addObject("capPayId", capPayId);
		view.addObject("proIntId", proIntId);
		view.addObject("opnTypCd", opnTypCd);
		view.addObject("procNm", procNm);
		view.addObject("payTypCd",payTypCdq);
        
		//是否
		List<KeyValueVO> yesOrNOList = this.audPayPassOpinionService.searchYesOrNOList();
		view.addObject("yesOrNOList", yesOrNOList);
		//挂靠mortgageCdList
		List<KeyValueVO> mortgageCdList = this.audPayPassOpinionService.searchMortgageCdList();
		view.addObject("mortgageCdList", mortgageCdList);
		
		Long prjPrdId = capPayInfoVO.getPrjPrdId();
        PrjPrdBscInfoVO prjPrdBscInfoVO = this.prjPrdBscInfoService.selectById(prjPrdId);
        if(null!=prjPrdBscInfoVO){
        	view.addObject("isNewPrd", prjPrdBscInfoVO.getIsNew());
        }
		Long prjId = capPayInfoVO.getPrjId();
		PrjBscInfoVO prjBscInfoVO = new PrjBscInfoVO();
		if(StringUtils.isNotEmpty(prjId)){
			prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
		}
		view.addObject("prjBscInfoVO", prjBscInfoVO);
		//查询放款通过意见
		AudPayPassOpinionVO audPayPassOpinionVO = new AudPayPassOpinionVO();
		if(StringUtils.isNotEmpty(capPayId) && StringUtils.isNotEmpty(proIntId)){
			AuditPayPassOpQueryCondition qc = new AuditPayPassOpQueryCondition();
			qc.setCapPayId(Long.valueOf(capPayId));
			qc.setProIntId(proIntId);
			qc.setOpnTypCd(opnTypCd);

			AudPayPassOpListRequest selectRequest = new AudPayPassOpListRequest(qc);
			ResponseData<List<AuditPayPassOpinionDTO>> responseData = auditPayPassOpinionService.searchAudPayPassOpinionList(selectRequest);
			if (responseData != null && ResponseData.SUCCESS_CODE.equals(responseData.getCode()) && responseData.getData() != null) {
				List<AuditPayPassOpinionDTO> payPassOpinionDTOS = responseData.getData();
				if (CollectionUtils.isNotEmpty(payPassOpinionDTOS)) {
					AuditPayPassOpinionDTO auditPayPassOpinionDTO = payPassOpinionDTOS.get(0);
					BeanUtils.copyProperties(auditPayPassOpinionDTO, audPayPassOpinionVO);
					audPayPassOpinionVO.setCapPayId(auditPayPassOpinionDTO.getPayId());
					audPayPassOpinionVO.setOpnTypCd(auditPayPassOpinionDTO.getTypeCd());
					if (null != auditPayPassOpinionDTO.getPayAmt()) {
						audPayPassOpinionVO.setPayAmtDouble(DecimalUtils.convertFenToYuan(auditPayPassOpinionDTO.getPayAmt()));
					}
					if (null != auditPayPassOpinionDTO.getIncomeAmt()) {
						audPayPassOpinionVO.setIncomeAmtDouble(DecimalUtils.convertFenToYuan(auditPayPassOpinionDTO.getIncomeAmt()));
					}
				}
			}
		}
		view.addObject("capPayInfoVO", capPayInfoVO);
		view.addObject("audPayPassOpinionVO", audPayPassOpinionVO);
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String searchName = request.getParameter("demo.name");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		AudPayPassOpinionQueryCondition qc = new AudPayPassOpinionQueryCondition();
		if (StringUtils.isNotEmpty(searchName)) {
		}
		page.setCondition(qc);

		Pager pager = new Pager();//this.audPayPassOpinionService.searchListPage(page);
		List<AudPayPassOpinionVO> list = (List<AudPayPassOpinionVO>) pager.getResultList();
		ListPageVO<AudPayPassOpinionVO> listPage = new ListPageVO<AudPayPassOpinionVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.audPayPassOpinionService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AudPayPassOpinionVO vo = this.audPayPassOpinionService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		AudPayPassOpinionVO entity = null;
		try {
			entity = getRequestParamForAdd(request);

			AuditPayPassOpinionDTO auditPayPassOpinionDTO = new AuditPayPassOpinionDTO();
			BeanUtils.copyProperties(entity, auditPayPassOpinionDTO);
			auditPayPassOpinionDTO.setPayId(entity.getCapPayId());
			auditPayPassOpinionDTO.setTypeCd(entity.getOpnTypCd());
			AddAudPayPassOpRequest addRequest = new AddAudPayPassOpRequest(auditPayPassOpinionDTO);
			ResponseData<Long> responseData = auditPayPassOpinionService.addAudPayPassOpinion(addRequest);
			if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
				throw new BaseException(BaseExceptionConstant.DATABASE_0201_NAME, "新增数据失败");
			}
			result.setData(responseData.getData());
			BaseLogUtils.info(logger, "add", "新增数据.[id="+responseData.getData()+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		AudPayPassOpinionVO entity = null;
		try {
			entity = getRequestParamForModify(request);
			entity.setId(Long.valueOf(id));

			AuditPayPassOpinionDTO auditPayPassOpinionDTO = new AuditPayPassOpinionDTO();
			BeanUtils.copyProperties(entity, auditPayPassOpinionDTO);
			auditPayPassOpinionDTO.setPayId(entity.getCapPayId());
			auditPayPassOpinionDTO.setTypeCd(entity.getOpnTypCd());
			ModifyAudPayPassOpRequest modifyRequest = new ModifyAudPayPassOpRequest(auditPayPassOpinionDTO);

			ResponseData responseData = auditPayPassOpinionService.modifyAudPayPassOpinion(modifyRequest);
			if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 获取参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private AudPayPassOpinionVO getRequestParam(HttpServletRequest request)throws BaseException{
		String capPayId = request.getParameter("capPayId");
		String proIntId = request.getParameter("proIntId");
		String opnTypCd = request.getParameter("opnTypCd");
		if(StringUtils.isEmpty(capPayId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "付款信息ID不能为空.");
		}
		if(StringUtils.isEmpty(proIntId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "流程实例ID不能为空.");
		}
		if(StringUtils.isEmpty(opnTypCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "放款通过意见类型不能为空.");
		}
		String isFullInsurance = request.getParameter("isFullInsurance");
		String isComplianceBeneficiary = request.getParameter("isComplianceBeneficiary");
		String isCompleteInsurance = request.getParameter("isCompleteInsurance");
		String isTransfer = request.getParameter("isTransfer");
		String isAnchored = request.getParameter("isAnchored");
		String remark = request.getParameter("remark");
		String isMortgage = request.getParameter("isMortgage");
		String mortgageCd = request.getParameter("mortgageCd");
		String isHavePhoto = request.getParameter("isHavePhoto");
		String payAmt = request.getParameter("payAmt");
		String incomeAmt = request.getParameter("incomeAmt");
		String isNewPrd = request.getParameter("isNewPrd");
		String isUploadIns = request.getParameter("isUploadIns");
		
		String carAudit = request.getParameter("carAudit");
		String busAudit = request.getParameter("busAudit");
		
		if(StringUtils.isNotEmpty(busAudit)){
			
		}else if(StringUtils.isNotEmpty(carAudit)){
			/**乘用车放款意见校验*/
			if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_CONTRACT)){
				//校验乘用车合同必填
				if(StringUtils.isNotEmpty(isNewPrd) && "1".equals(isNewPrd)){//新车
					if(StringUtils.isEmpty(payAmt)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "应付金额不能为空.");
					}
					if(StringUtils.isEmpty(incomeAmt)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "应收款不能为空.");
					}
				}else if (StringUtils.isEmpty(isNewPrd) && "0".equals(isNewPrd)){//二手车
					if(StringUtils.isEmpty(isFullInsurance)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "保险是否足额不能为空.");
					}
					if(StringUtils.isEmpty(isComplianceBeneficiary)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "第一受益人是否合规不能为空.");
					}
					if(StringUtils.isEmpty(isCompleteInsurance)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "险种是否齐全不能为空.");
					}
					if(StringUtils.isEmpty(isTransfer)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否过户不能为空.");
					}
					if(StringUtils.isEmpty(isMortgage)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否抵押不能为空.");
					}
					//TODO 如果二手车正常放款 还需校验两个金额
				}
			}else if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_MORTGAGE)){
				if(StringUtils.isEmpty(isMortgage)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否办理抵押不能为空.");
				}
				if(StringUtils.isEmpty(isHavePhoto)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "交车照片不能为空.");
				}
			}
		}else{
			/**重卡放款意见校验*/
			/*if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_CONTRACT)){
				//校验合同必填
				if(StringUtils.isEmpty(isFullInsurance)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "保险是否足额不能为空.");
				}
				if(StringUtils.isEmpty(isComplianceBeneficiary)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "第一受益人是否合规不能为空.");
				}
				if(StringUtils.isEmpty(isCompleteInsurance)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "险种是否齐全不能为空.");
				}
				if(StringUtils.isEmpty(isTransfer)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否过户不能为空.");
				}
				if(StringUtils.isEmpty(isAnchored)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否挂靠不能为空.");
				}
				
			}else if(opnTypCd.equals(AudStandingBookConstant.AUD_PAY_OPN_TYP_CD_MORTGAGE)){
				//校验抵押必填
				if(StringUtils.isEmpty(isMortgage)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否办理抵押不能为空.");
				}
				if(StringUtils.isEmpty(mortgageCd)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "挂靠不能为空.");
				}
				if(StringUtils.isEmpty(isHavePhoto)){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "交车照片不能为空.");
				}
			}*/
		}
		
		AudPayPassOpinionVO audPayPassOpinionVO = new AudPayPassOpinionVO();
		if(StringUtils.isNotEmpty(capPayId)){
			audPayPassOpinionVO.setCapPayId(Long.valueOf(capPayId));
		}
		audPayPassOpinionVO.setProIntId(proIntId);
		audPayPassOpinionVO.setOpnTypCd(opnTypCd);
		if(StringUtils.isNotEmpty(isFullInsurance)){
			audPayPassOpinionVO.setIsFullInsurance(Integer.valueOf(isFullInsurance));
		}
		if(StringUtils.isNotEmpty(isComplianceBeneficiary)){
			audPayPassOpinionVO.setIsComplianceBeneficiary(Integer.valueOf(isComplianceBeneficiary));
		}
		if(StringUtils.isNotEmpty(isCompleteInsurance)){
			audPayPassOpinionVO.setIsCompleteInsurance(Integer.valueOf(isCompleteInsurance));
		}
		if(StringUtils.isNotEmpty(isTransfer)){
			audPayPassOpinionVO.setIsTransfer(Integer.valueOf(isTransfer));
		}
		if(StringUtils.isNotEmpty(isAnchored)){
			audPayPassOpinionVO.setIsAnchored(Integer.valueOf(isAnchored));
		}
		if(StringUtils.isNotEmpty(isMortgage)){
			audPayPassOpinionVO.setIsMortgage(Integer.valueOf(isMortgage));
		}
		audPayPassOpinionVO.setMortgageCd(mortgageCd);
		if(StringUtils.isNotEmpty(isHavePhoto)){
			audPayPassOpinionVO.setIsHavePhoto(Integer.valueOf(isHavePhoto));
		}
		if(StringUtils.isNotEmpty(payAmt)){
			audPayPassOpinionVO.setPayAmt(DecimalUtils.convertYuanToFen(Double.valueOf(payAmt)));
		}
		if(StringUtils.isNotEmpty(incomeAmt)){
			audPayPassOpinionVO.setIncomeAmt(DecimalUtils.convertYuanToFen(Double.valueOf(incomeAmt)));
		}
		audPayPassOpinionVO.setRemark(remark);
		if(StringUtils.isNotEmpty(isUploadIns)){
			audPayPassOpinionVO.setIsUploadIns(Integer.valueOf(isUploadIns));
		}
		return audPayPassOpinionVO;
	}
	
	/**
	 * 获取请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private AudPayPassOpinionVO getRequestParamForAdd(HttpServletRequest request)throws BaseException{
		AudPayPassOpinionVO audPayPassOpinionVO = this.getRequestParam(request);
		audPayPassOpinionVO.setCrtTm(new Date());
		audPayPassOpinionVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		return audPayPassOpinionVO;
	}
	
	/**
	 * 获取请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private AudPayPassOpinionVO getRequestParamForModify(HttpServletRequest request)throws BaseException{
		AudPayPassOpinionVO audPayPassOpinionVO = this.getRequestParam(request);
		audPayPassOpinionVO.setMdfTm(new Date());
		audPayPassOpinionVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return audPayPassOpinionVO;
	}
}

